package com.zwh.autoconfigure.web.converter;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.zwh.common.mapper.JsonMapper;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

/**
 * @Author monkey
 * @Date 2019/12/25 14:37
 **/
@Configuration
public class JacksonHttpMessageConvertersConfig {
    /*@Autowired
    private Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder;*/

    /*@Bean
    @Primary
    public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
        System.out.println("进入jackson配置");
//        ObjectMapper mapper = jackson2ObjectMapperBuilder.build();
        JsonMapper mapper = JsonMapper.getInstance();
        return new MappingJackson2HttpMessageConverter(mapper);
    }*/
    @Bean
    @Primary
    @ConditionalOnMissingBean(ObjectMapper.class)
    public ObjectMapper jacksonObjectMapper()
    {
//        System.out.println("进入jackson配置");
        JsonMapper mapper = JsonMapper.getInstance();
//        DateFormat dateFormat = mapper.getDateFormat();
//        DateFormat myDateFormat = new MyDateFormat(dateFormat);
//        mapper.setDateFormat(myDateFormat);

        return mapper;
    }
}
